package com.luculent.result;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.luculent.base.RCode;

public class Response{
	
	public Response(){}
	
	public Response(String code,String msg){
		this.head.rtnCode = code;
		this.head.rtnMsg = msg;
	}
	
	public Head head = new Head();
	public Body body = new Body();
	
	public String toJson(){
		Gson gson = new GsonBuilder().disableHtmlEscaping().create();
		return gson.toJson(this);
	}
	
	public class Head {
		public String rtnMsg = "请求发生异常";
		public String rtnCode = RCode.dass999999;
	}

	public class Body {
		public String totalCount;
		public String size;
		public String sql;
		public String total;
		public String page;
	} 
	
	public static String noLogin(){
		Gson gson = new GsonBuilder().disableHtmlEscaping().create(); 
		return gson.toJson(new Response(RCode.dass900001,"未登录或登录超时"));
	}
	
	public static String fail(){
		Gson gson = new GsonBuilder().disableHtmlEscaping().create(); 
		return gson.toJson(new Response());
	}
	
	public static String fail(String code,String msg){
		Gson gson = new GsonBuilder().disableHtmlEscaping().create(); 
		return gson.toJson(new Response(code,msg));
	}
	
	public static Response ok(){ 
		return new Response(RCode.dass000000,"查询成功");
	}
	
	public static String okJson(){  
		return new GsonBuilder().disableHtmlEscaping().create().toJson(new Response(RCode.dass000000,"查询成功"));
	}
	
}